Imports Microsoft.VisualStudio.DebuggerVisualizers

Public Class frmStringVisualizer

#Region " Declarations "

    Private _objObjectProvider As _
        IVisualizerObjectProvider

#End Region

#Region " Properties "

    Public Property ObjectProvider() As _
        IVisualizerObjectProvider
        Get
            Return _objObjectProvider
        End Get
        Set(ByVal Value As IVisualizerObjectProvider)
            _objObjectProvider = Value
        End Set
    End Property

    Public Property StringToVisualize() As String
        Get
            Return Me.txtString.Text
        End Get
        Set(ByVal Value As String)
            Me.txtString.Text = Value
        End Set
    End Property

#End Region

#Region " Methods "

    Private Sub btnClose_Click(ByVal sender As _
        System.Object, ByVal e As System.EventArgs) _
        Handles btnClose.Click
        Me.Close()

    End Sub

    Private Sub btnReplaceText_Click(ByVal sender As _
        System.Object, ByVal e As System.EventArgs) _
        Handles btnReplaceText.Click
        'There are two ways to replace data.  Take your choice.
        '
        '1.  use the ReplaceData Method
        Using ms As New System.IO.MemoryStream
            StringVisualizerObjectSource.Serialize( _
                ms, Me.StringToVisualize)
            ObjectProvider.ReplaceData(ms)
            ms.Close()
        End Using
        '2.  use the ReplaceObject Method
        'ObjectProvider.ReplaceObject(Me.StringToVisualize)
        Me.Close()

    End Sub

    Private Sub frmStringVisualizer_Load(ByVal sender _
        As System.Object, ByVal e As _
        System.EventArgs) Handles MyBase.Load
        Me.btnReplaceText.Enabled = _
            Me.ObjectProvider.IsObjectReplaceable

        If Me.btnReplaceText.Enabled Then
            Me.ToolTip1.SetToolTip(Me.btnReplaceText, _
                "Click to replace the original text with what you " _
                & _
                "have entered in the above textbox.")

        Else
            Me.ToolTip1.SetToolTip(Me.btnReplaceText, _
                "The source object does not support replacement.")
        End If

    End Sub

    Private Sub txtString_TextChanged(ByVal sender As _
        Object, ByVal e As System.EventArgs) Handles _
        txtString.TextChanged
        Me.lblStringLength.Text = String.Format( _
            "{0} characters", _
            Me.txtString.Text.Trim.Length)

    End Sub

#End Region

End Class
